import { createStore, Store, useStore as baseUseStore } from 'vuex'
import getters from './getters'
import app from './modules/app'
import settings from './modules/settings'
import user from './modules/user'
import permission from './modules/permission'
import parameter from './modules/parameter'
import common from './modules/common'
import issue from './modules/issue'
import type { PassState } from './modules/pass'
import { InjectionKey } from 'vue';
import { createPinia } from 'pinia'

interface State {
  pass: PassState
}

const pinia = createPinia()

export const key: InjectionKey<Store<State>> = Symbol();

const store = createStore<State>({
  modules: {
    app,
    settings,
    user,
    permission,
    common,
    issue,
    parameter    
  },
  getters
})

export const setupStore = (app) => {
  app.use(store)
  app.use(pinia)
}

export function useStore () {
  return baseUseStore(key)
}


export default store
